using System.Collections.Generic;

namespace Triton.Common.Math
{
	public struct BoundingBox2
	{
		public Vector2 Min;

		public Vector2 Max;

		public BoundingBox2(Vector2 min, Vector2 max)
		{
			Min = min;
			Max = max;
		}

		public bool Contains(Vector2 v)
		{
			if (v.X >= Min.X && v.X <= Max.X && v.Y >= Min.Y)
			{
				return v.Y <= Max.Y;
			}
			return false;
		}

		public static BoundingBox2 CreateFromPoints(IEnumerable<Vector2> points)
		{
			BoundingBox2 result = new BoundingBox2(new Vector2(float.MaxValue, float.MaxValue), new Vector2(float.MinValue, float.MinValue));
			bool flag = false;
			foreach (Vector2 point in points)
			{
				Vector2 v = point;
				flag = true;
				Vector2.Min(ref result.Min, ref v, out result.Min);
				Vector2.Max(ref result.Max, ref v, out result.Max);
			}
			if (!flag)
			{
				return default(BoundingBox2);
			}
			return result;
		}
	}
}
